//需要避免的手机号
const signTel=[
  '18742020281',
  '18642691383'
];

/**
 * @author CHZH
 * @date 2018/5/5 0005
 * @Description: 模拟数据
 */
export default class api {
  constructor() {
    this.ordernum=1000+Math.floor(Math.random()*9000);
    this.firstName=[
'赵','钱','孙','李','周','吴','郑','王',
'冯','陈','褚','卫','蒋','沈','韩','杨',
'朱','秦','尤','许','何','吕','施','张',
'孔','曹','严','华','金','魏','陶','姜',
'戚','谢','邹','喻','柏','水','窦','章',
'云','苏','潘','葛','奚','范','彭','郎',
'鲁','韦','昌','马','苗','凤','花','方',
'俞','任','袁','柳','酆','鲍','史','唐',
'费','廉','岑','薛','雷','贺','倪','汤',
'滕','殷','罗','毕','郝','邬','安','常',
'乐','于','时','傅','皮','卞','齐','康',
'伍','余','元','卜','顾','孟','平','黄',
'和','穆','萧','尹','姚','邵','湛','汪',
'祁','毛','禹','狄','米','贝','明','臧',
'计','伏','成','戴','谈','宋','茅','庞',
'熊','纪','舒','屈','项','祝','董','梁',
'杜','阮','蓝','闵','席','季','麻','强',
'贾','路','娄','危','江','童','颜','郭',
'梅','盛','林','刁','钟','徐','邱','骆',
'高','夏','蔡','田','樊','胡','凌','霍',
'虞','万','支','柯','昝','管','卢','莫',
'经','房','裘','缪','干','解','应','宗',
'丁','宣','贲','邓','郁','单','杭','洪',
'包','诸','左','石','崔','吉','钮','龚',
'程','嵇','邢','滑','裴','陆','荣','翁',
'荀','羊','於','惠','甄','曲','家','封',
'芮','羿','储','靳','汲','邴','糜','松',
'井','段','富','巫','乌','焦','巴','弓',
'牧','隗','山','谷','车','侯','宓','蓬',
'全','郗','班','仰','秋','仲','伊','宫',
'宁','仇','栾','暴','甘','钭','厉','戎',
'祖','武','符','刘','景','詹','束','龙',
'叶','幸','司','韶','郜','黎','蓟','薄',
'印','宿','白','怀','蒲','邰','从','鄂',
'索','咸','籍','赖','卓','蔺','屠','蒙',
'池','乔','阴','鬱','胥','能','苍','双',
'闻','莘','党','翟','谭','贡','劳','逄',
'姬','申','扶','堵','冉','宰','郦','雍',
'卻','璩','桑','桂','濮','牛','寿','通',
'边','扈','燕','冀','郏','浦','尚','农',
'温','别','庄','晏','柴','瞿','阎','充',
'慕','连','茹','习','宦','艾','鱼','容',
'向','古','易','慎','戈','廖','庾','终',
'暨','居','衡','步','都','耿','满','弘',
'匡','国','文','寇','广','禄','阙','东',
'欧','殳','沃','利','蔚','越','夔','隆',
'师','巩','厍','聂','晁','勾','敖','融',
'冷','訾','辛','阚','那','简','饶','空',
'曾','毋','沙','乜','养','鞠','须','丰',
'巢','关','蒯','相','查','后','荆','红',
'游','竺','权','逯','盖','益','桓','公',
'万','俟','司','马','上','官','欧','阳',
'夏','侯','诸','葛','闻','人','东','方',
'赫','连','皇','甫','尉','迟','公','羊',
'澹','台','公','冶','宗','政','濮','阳',
'淳','于','单','于','太','叔','申','屠',
'公','孙','仲','孙','轩','辕','令','狐',
'钟','离','宇','文','长','孙','慕','容',
'鲜','于','闾','丘','司','徒','司','空',
'丌','官','司','寇','仉','督','子','车',
'颛','孙','端','木','巫','马','公','西',
'漆','雕','乐','正','壤','驷','公','良',
'拓','跋','夹','谷','宰','父','谷','梁',
'晋','楚','闫','法','汝','鄢','涂','钦',
'段','干','百','里','东','郭','南','门',
'呼','延','归','海','羊','舌','微','生',
'岳','帅','缑','亢','况','郈','有','琴',
'梁','丘','左','丘','东','门','西','门',
'商','牟','佘','佴','伯','赏','南','宫',
'墨','哈','谯','笪','年','爱','阳','佟'];
    this.lastName=[
      '若梅','巧露','诗柔','翠珍','香蕾','春兰','涵芹','雅薇','元萱','碧容','乐薇','采晴','秋萍','晓晴','诗蕾','诗灵','曼玉','梦芹','晓菱','晓露','晓萱','芷巧','碧菱','曼雪','绮萍','巧云','香梅','春儿','青萍','迎珍','秋之','晓萱','怀云','梦秋','绮兰','紫丝','紫露','灵冬','怀瑶','怜风','香珊','妙蕊','水珍','雪桃','易蓉','乐晴','初真','秋竹','诗凝','沛薇','凝晴','香薇','凝梅','怜兰','绮文','语薇','冷桃','书蝶','紫萍','梦之','夏云','香晴','紫云',
      '维','伟','超','芳','娜','敏','静','秀英','黎','丽','利','强','阳','洋','君','磊','艳','勇','娟','涛','超','霞','军','平','晖','燕','丹','萍','桂英','玉兰','秀兰','铃','玲','宇','秀珍','莉','慧','斌','彬彬','凯','刚','林','鹏','建','冬梅','龙','志强','余华','玉华','建国','建军','婷','云','勇','洁','明','亮','鑫','欣','路','璐','兵','文','柳','晨','璐','成','杨','楠','风','凤','宁','健','洁','晶','帅','凯','琴','颖','惠','俊杰','俊','波','浩','子轩','瑾轩','梦琪','梓涵','思涵','雨涵','诗涵','可欣','梓萌','一诺','可欣','若曦','心怡','若曦','诗琪','雨桐','紫萱','浩然','子轩','皓轩','宇轩','梓睿','梓轩','皓轩','梓豪','子墨','博文','睿','子豪','宇航','致远','天佑','明轩','俊豪','皓然','昊然','子宸','如意'
    ];
    this.firstName_En = [
      'Kelly',
      'O\'Sullivan',
      'Walsh',
      'Smith',
      'O\'Brien',
      'Byrne',
      'Ryan',
      'O\'Connor',
      'O\'Neil',
      'McCarthy',
      'Doyle',
      'Allagher',
      'O\'Doherty',
      'Kennedy',
      'Lynch',
      'Murray',
      'Murray',
      'Quinn',
      'Moore',
      'Cohen',
      'Williams',
      'Jones',
      'Brown',
      'Davis',
      'Miller',
      'Wilson',
      'Moore',
      'Taylor',
      'Anderson',
      'Thomas',
      'Jackson',
      'White',
      'Harris',
      'Martin',
      'Thompson',
      'Garcia',
      'Martinez',
      'Robinson'
    ];
    this.lastName_En = [
      'Jacob',
      'Michael',
      'Ethan',
      'Joshua',
      'Alexander',
      'Anthony',
      'Christopher',
      'Jayden',
      'Anderew',
      'Joseph',
      'David',
      'Noad',
      'Aiden',
      'James',
      'Ryan',
      'Logan',
      'John',
      'Nathan',
      'Elijah',
      'Christian',
      'Benjamin',
      'Jonathan',
      'Tyler',
      'Samuel',
      'Nicholas',
      'Gavin',
      'Samuel',
      'Nicholans',
      'Gavin',
      'Dylan',
      'Jackson',
      'Dylan',
      'Jackson',
      'Brandon',
      'Caleb',
      'Angel',
      'Isaac',
      'Evan',
      'Kevin',
      'Jose',
      'Isaiah',
      'Luke',
      'Landon',
      'Justin',
      'Lucas',
      'Jordan',
      'Robert',
      'Aaron',
      'Thomas'
    ];
    this.materialIndex = [
      'nectarine',
      'pumpkin cushaw',
      'beef',
      'pork',
      'mutton',
      'lamb',
      'chicken',
      'lettuce',
      'cabbage',
      'cabbage',
      'radish',
      'carrot',
      'leek',
      'agarics',
      'pea',
      'potato',
      'cucumber',
      'cucumber',
      'balsam pear',
      'okra',
      'onion',
      'celery',
      'celery sticks',
      'sweet potato',
      'sticks',
      'mushroom',
      'olive',
      'spinach',
      'wax gourd',
      'lotus root',
      'laver',
      'cole rape',
      'eggplant',
      'tendon',
      'pork joint',
      'fennel',
      'carp',
      'bacon',
      'needle mushroom',
      'lentil',
      'areca',
      'great burdock',
      'summer radish',
      'bamboo shoot',
      'mugwort',
      'mung bean',
      'green soy bean',
      'cushaw',
      'sweet corn',
      'vinegar',
      'soy',
      'salt',
      'iodized salt',
      'sugar',
      'refined sugar',
      'salad',
      'hot pepper',
      'black pepper',
      'wild pepper',
      'salad oil',
      'fixing sauce seasoning',
      'granulated suger',
      'brown sugar',
      'rock sugar',
      'sesame',
      'sesame paste',
      'sesame oil',
      'curry',
      'ketchup redeye',
      'horseradish',
      'ginger',
      'garlic',
      'cooking wine',
      'oyster sauce',
      'medlar',
      'aniseed',
      'yeast barm',
      'yello pepper',
      'cinnamon',
      'butter',
      'banilla',
    ];
    this.address1 = [
      '大连市'
    ];
    this.address2 = [
      {
        name: '西岗区',
        list: ['香炉礁街道', '白云街道', '八一路街道', '站北街道', '日新街道', '人民广场街道', '北京街道']
      },
      {
        name: '中山区',
        list: ['民主街道', '桂林街道', '昆明街道', '虎滩街道', '天津街道', '青泥街道', '春海街道', '葵英街道', '春和街道', '桃源街道', '枫林街道', '转山街道', '明泽街道']
      },
      {
        name: '沙河口区',
        list: ['中山公园街道', '白山路街道', '星海湾街道', '黑石礁街道', '南沙河口街道', '马栏街道', '李家街道', '兴工街道', '春柳街道']
      },
      {
        name: '甘井子区',
        list: ['周水子街道', '椒金山街道', '甘井子街道', '南关岭街道', '泡崖街道', '中华路街道', '兴华街道', '机场街道', '辛寨子街道', '红旗街道', '凌水街道', '大连湾街道', '泉水街道', '革镇堡街道', '营城子街道',]
      },
      {
        name: '高新园区',
        list: ['凌水街道', '龙王塘街道']
      },
      {
        name: '旅顺口区',
        list: ['登峰街道', '市场街道', '得胜街道', '光荣街道', '水师营街道', '龙王塘街道', '铁山街道', '双岛湾街道', '三涧堡街道', '长城街道', '龙头街道', '北海街道']
      },
      {
        name: '金州区',
        list: ['拥政街道', '友谊街道', '光明街道', '马桥子街道', '海青岛街道', '大孤山街道', '中长街道', '站前街道', '先进街道', '新港街道', '董家沟街道', '金石滩街道', '湾里街道', '二十里堡街道', '三十里堡街道', '亮甲店街道', '登沙河街道', '杏树街道', '石河街道', '大魏家街道', '七顶山街道', '向应街道', '华家街道', '大李家街道', '得胜街道']
      },
      {
        name: '普兰店区',
        list: ['丰荣街道', '铁西街道', '太平街道', '南山街道', '杨树房街道', '大刘家街道', '皮口街道', '城子坦街道', '唐家房街道', '大谭街道', '莲山街道']
      },
      {
        name: '瓦房店区',
        list: ['文兰街道', '共济街道', '铁东街道', '岭东街道', '祝华街道', '岗店街道', '新华街道', '太阳街道', '九龙街道']
      },
      {
        name: '庄河区',
        list: ['城关街道', '新华街道', '兴达街道', '昌盛街道', '明阳街道', '青堆镇', '徐岭镇', '黑岛镇']
      },
      {
        name: '长兴岛区',
        list: ['长兴岛街道', '交流岛街道']
      }
    ];
    this.status = [
      'waiting','waiting','waiting','waiting','waiting','waiting','waiting','waiting',
      'sending','sending','sending','sending','sending',
      'warning',
      'success','success','success',
      'cancelled',
    ];
    this.menu=[
      {
        name:'白菜猪肉饺子',
        list:['白菜','猪肉','面粉','鸡蛋','盐'],
        price:25
      },
      {
        name:'白菜牛肉饺子',
        list:['白菜','牛肉','面粉','鸡蛋','盐'],
        price:28
      },
      {
        name:'虾仁三鲜饺子',
        list:['猪肉','虾仁','冬笋','盐','味精','蛋清','生粉'],
        price:35
      },
      {
        name:'猪肉韭菜饺子',
        list:['猪肉','盐','五香粉','生抽','熟油','香油','料酒','韭菜','面粉'],
        price:28
      },
      {
        name:'牛肉韭菜饺子',
        list:['牛肉','盐','五香粉','生抽','熟油','香油','料酒','韭菜','面粉'],
        price:29
      },
      {
        name:'韭菜鸡蛋饺子',
        list:['面粉','韭菜','鸡蛋','木耳','盐','酱油'],
        price:24
      },
      {
        name:'韭菜木耳饺子',
        list:['面粉','韭菜','木耳','盐','酱油'],
        price:24
      },
      {
        name:'花泽香菜饺子',
        list:['香菜','肉馅','十三香','盐','面粉','鸡蛋','酱油'],
        price:24
      },
      {
        name:'冬菇鲜肉饺子',
        list:['猪肉','冬菇丁','油葱酥','盐','糖','五香粉'],
        price:25
      },
      {
        name:'驴肉鸡蛋饺子',
        list:['驴肉','猪肉','胡萝卜','洋葱','鸡蛋','盐','料酒','姜粉','味精','酱油'],
        price:30
      },
      {
        name:'牛肉鸡蛋饺子',
        list:['牛肉','猪肉','胡萝卜','洋葱','鸡蛋','盐','料酒','姜粉','味精','酱油'],
        price:30
      },
      {
        name:'吊瓜猪肉饺子',
        list:['猪肉','韭菜','吊瓜','盐','鸡精','姜','味精','五香粉','香油'],
        price:26
      },
      {
        name:'吊瓜牛肉饺子',
        list:['牛肉','韭菜','吊瓜','盐','鸡精','姜','味精','五香粉','香油'],
        price:28
      },
      {
        name:'黄花木耳饺子',
        list:['黄花菜','西葫芦','胡萝卜','黑木耳','鸡蛋','面粉','盐','生抽','味精'],
        price:24
      },
      {
        name:'刺五加馅饺子',
        list:['刺五加','猪肉','葱末','姜末','盐','酱油'],
        price:26
      },
      {
        name:'鲅鱼韭菜饺子',
        list:['鲅鱼','猪肉','韭菜','盐','酱油','面粉'],
        price:35
      },
      {
        name:'菠菜粉丝饺子',
        list:['菠菜','粉丝','鸡蛋','面粉','面酱','酱油','盐','味精'],
        price:22
      },
      {
        name:'胡萝卜猪肉饺子',
        list:['猪肉','胡萝卜','面粉','生抽','芝麻油','盐'],
        price:26
      },
      {
        name:'胡萝卜牛肉饺子',
        list:['牛肉','胡萝卜','面粉','生抽','芝麻油','盐'],
        price:26
      },
      {
        name:'香芹猪肉饺子',
        list:['猪肉','香芹','面粉','酱油','盐'],
        price:26
      },
      {
        name:'香芹牛肉饺子',
        list:['牛肉','香芹','面粉','酱油','盐'],
        price:28
      },
      {
        name:'茴香猪肉饺子',
        list:['猪肉','茴香','面粉','酱油','盐'],
        price:26
      },
      {
        name:'茴香牛肉饺子',
        list:['牛肉','茴香','面粉','酱油','盐'],
        price:28
      },
      {
        name:'芹菜猪肉饺子',
        list:['猪肉','芹菜','面粉','酱油','盐'],
        price:26
      },
      {
        name:'芹菜牛肉饺子',
        list:['牛肉','芹菜','面粉','酱油','盐'],
        price:28
      },
      {
        name:'泡菜猪肉饺子',
        list:['猪肉','泡菜','面粉','酱油','盐'],
        price:27
      },
      {
        name:'泡菜牛肉饺子',
        list:['牛肉','泡菜','面粉','酱油','盐'],
        price:29
      },
      {
        name:'豆角猪肉饺子',
        list:['猪肉','豆角','面粉','酱油','盐'],
        price:28
      },
      {
        name:'豆角牛肉饺子',
        list:['牛肉','豆角','面粉','酱油','盐'],
        price:30
      },
      {
        name:'西红柿鸡蛋饺子',
        list:['鸡蛋','西红柿','面粉','酱油','盐'],
        price:24
      },
      {
        name:'鱼香肉丝饺子',
        list:['胡萝卜','香菇','辣椒','猪肉','面粉','酱油','盐'],
        price:28
      },
    ];
    this.userList = [];
    this.userMap=new Map();
    this.senderList = [];
    this.managerList = [];
    this.managerMap=new Map();
    this.orderList = [];
    this.branchOrder=[];
    this.branchList = [];
    this.totalListMap=new Map();
    this.totalList=[];
    this.branchStore=[];
    this.telStore=new Set(signTel);
    this.init();
  }

  addOrderList(data){
    const Tuser=data.user,
      menuindex=data.index,
      menunumber=data.number,
      time=data.date.toLocaleString(),
      date=data.date.getTime(),
      status='waiting',
      sender=this.senderList[Math.floor(Math.random() * this.senderList.length)].username,
      price='￥'+this.menu[menuindex].price*menunumber,
      user=Tuser.username,
      material=this.menu[menuindex].list[0],
      burdening=this.menu[menuindex].list[1]
    ;
    const add1=Tuser.add1,
      add2=Tuser.add2,
      add3=Tuser.add3
    ;
    let branchnum=Math.floor(Math.random() * 10);
    for (const branchListElement of this.branchList) {
      if(add2===branchListElement.address.add2){
        branchnum=branchListElement.id;
      }
    }
    this.orderList.push({
      id:this.ordernum,
      status:status,
      branch:branchnum,
      sender:sender,
      time:time,
      date:date,
      price:price,
      user:user,
      tUser:Tuser,
      material:material,
      burdening:burdening
    });
    this.branchOrder[branchnum].push(this.ordernum++);
    this.orderList.sort((a,b)=>b.date-a.date);
  }

  getOrderList(branch = null, index = 0, number =10) {
    let list = [];
    let k = index*number;
    while (list.length < number && k < this.orderList.length) {
      if ((!branch&&branch!==0) || this.orderList[k].branch === branch) {
        list.push(this.orderList[k]);
      }
      k++;
    }
    return list;
  }

  getOrderTotalByUser(user){
    // console.log(user);
    let total=0;
    for (const item of this.orderList) {
      // console.log(item);
      if(item.tUser.id === user.id){
        total++;
      }
    }
    return total;
  }

  getOrderTotalByBranch(branch){
    let total=0;
    for (const item of this.orderList) {
      if(item.branch === branch){
        total++;
      }
    }
    return total;
  }

  getOrderListByUser(user, index = 0, number =10) {
    let list = [];
    let k = index*number;
    while (list.length < number && k < this.orderList.length) {
      if (this.orderList[k].tUser.id === user.id) {
        list.push(this.orderList[k]);
      }
      k++;
    }
    return list;
  }


  getBranchList(){
    let list=[];
    for (let i = 0; i < 10; i++) {
      let waiting=0,warning=0;
      for (let j = 0; j < this.branchOrder[i].length; j++) {
        if(this.orderList[this.branchOrder[i][j]].status==='waiting') {
          waiting++;continue;
        }
        if(this.orderList[this.branchOrder[i][j]].status==='warning') {
          warning++;
        }
      }
      list.push({
        id:this.branchList[i].id,
        address:this.branchList[i].address.add1+this.branchList[i].address.add2+this.branchList[i].address.add3+this.branchList[i].add4,
        manager:this.branchList[i].manager.username,
        telephone:this.branchList[i].manager.telephone,
        order:`Wait:${waiting}  Warn:${warning}`
      })
    }
    return list;
  }

  getTotalList(index=0,number=10){
    let list =[];
    for(let i=index*number;i<this.totalList.length&&i<(index+1)*number;i++){
      list.push(this.totalList[i]);
    }
    return list;
  }

  getBranchStore(branch=0,index=0,number=10){
    let list=[];
    for (let i = index*number; i < (index+1)*number&&i<this.branchStore[branch].length ; i++) {
      list.push(this.branchStore[branch][i]);
    }
    return list;
  }

  getManagerList(){
    return this.managerList;
  }

  getUserList(index=0,number=10){
    // return this.userList;
    let list=[];
    for (let i = index*number; i < (index+1)*number; i++) {
      list.push(this.userList[i]);
    }
    return list;
  }

  getMenu(){
    return this.menu;
  }

  setUser(info){

  }

  deleteManager(id){
    for (let i = 0; i < this.managerList.length; i++) {
      if(id==this.managerList[i].id){
        this.managerList.splice(i,1);
        return this.managerList;
      }
    }
  }

  deleteUser(id){
    for (let i = 0; i < this.userList.length; i++) {
      if(id==this.userList[i].id){
        this.userList.splice(i,1);
        return;
      }
    }
  }

  getDailySheet(range,branch){
    if(!range) return [];
    let list=[];
    for (const orderListElement of this.orderList) {
      if(branch==='total'||('branch'+(orderListElement.branch+1))===branch){
        const tempDate=new Date(orderListElement.date);
        const
          tYear=tempDate.getFullYear(),
          tMonth=tempDate.getMonth(),
          tDay=tempDate.getDay(),
          r0Year=range[0].getFullYear(),
          r0Month=range[0].getMonth(),
          r0Day=range[0].getDay(),
          r1Year=range[1].getFullYear(),
          r1Month=range[1].getMonth(),
          r1Day=range[1].getDay();
        // console.log(`Year ${tYear} ${r0Year} ${r1Year} ${tYear===r0Year&&tYear===r1Year}  : Month ${tMonth} ${r0Month} ${r1Month} ${tMonth===r0Month&&tMonth===r1Month}  :  Day ${tDay>=r0Day} ${tDay<=r1Day}`);
        let flag=false;
        if(tYear>=r0Year&&tYear<=r1Year){
          if(tYear===r0Year&&tYear===r1Year){
            if(tMonth>r0Month&&tMonth<r1Month){
              flag=true;
            }else if(tMonth===r0Month&&tMonth===r1Month&&tDay>=r0Day&&tDay<=r1Day){
              flag=true;
            }else if(tMonth===r0Month&&tMonth<r1Month&&tDay>=r0Day){
              flag=true;
            }else if(tMonth>r0Month&&tMonth===r1Month&&tDay<=r1Day){
              flag=true;
            }
          }else if(tYear>r0Year&&tYear<r1Year){
            flag=true;
          }else if(tYear===r0Year&&tYear<r1Year&&tMonth>=r0Month){
            flag=true;
          }else if(tYear>r0Year&&tYear===r1Year&&tMonth<=r1Month){
            flag=true;
          }
        }
        if(flag){
          list.push(orderListElement);
        }
      }

    }
    return list;
  }

  login(user){
    const username=user.username,
      password=user.password;
    if(username==='su'&&password==='123456'){
      return {
        error:null,
        data:{
          username:'su'
        }
      }
    }else if(this.managerMap.has(username)){
      if(password===this.managerList[this.managerMap.get(username)].password){
        return {
          error:null,
          data:{
            id:this.managerList[this.managerMap.get(username)].id,
            username:this.managerList[this.managerMap.get(username)].username,
            password:this.managerList[this.managerMap.get(username)].password,
            telephone:this.managerList[this.managerMap.get(username)].telephone,
            add1:this.managerList[this.managerMap.get(username)].add1,
            add2:this.managerList[this.managerMap.get(username)].add2,
            add3:this.managerList[this.managerMap.get(username)].add3,
            add4:this.managerList[this.managerMap.get(username)].add4,
          }
        }
      }else{
        return {
          error:'用户名或密码错误'
        }
      }
    }else if(this.userMap.has(username)){
      if(password===this.userList[this.userMap.get(username)].password){
        return {
          error:null,
          data:{
            id:this.userList[this.userMap.get(username)].id,
            username:this.userList[this.userMap.get(username)].username,
            password:this.userList[this.userMap.get(username)].password,
            telephone:this.userList[this.userMap.get(username)].telephone,
            add1:this.userList[this.userMap.get(username)].add1,
            add2:this.userList[this.userMap.get(username)].add2,
            add3:this.userList[this.userMap.get(username)].add3,
            add4:this.userList[this.userMap.get(username)].add4,
          }
        }
      }else{
        return {
          error:'用户名或密码错误'
        }
      }
    }else{
      return {
        error:'用户不存在'
      };
    }
  }
  signup(user){
    const
      username=user.username,
      password=user.password,
      telephone=user.telephone,
      add1=user.add1,
      add2=user.add2,
      add3=user.add3,
      add4=user.add4
    ;
    if(this.userMap.has(telephone)){
      return {
        error:'该电话号码已被注册'
      }
    }else{
      this.userMap.set(telephone,this.userList.length);
      const data={
        id:(parseInt(this.userList[this.userList.length-1].id)+1).toString(),
        username:username,
        password:password,
        telephone:telephone,
        address:add1+add2+add3+add4,
        add1:add1,
        add2:add2,
        add3:add3,
        add4:add4,
      };
      this.userList.push(data);
      return{
        error:null,
        data:data
      }
    }
  }
  /**
   * @author CHZH
   * @date 2018/5/5 0005
   * @Description: 随机生成姓名
   */
  ranName() {
    const ranFirstName = this.firstName[Math.floor(Math.random() * this.firstName.length)];
    const ranLastName = this.lastName[Math.floor(Math.random() * this.lastName.length)];
    return `${ranFirstName}${ranLastName}`;
  }


  /**
   * @author CHZH
   * @date 2018/5/5 0005
   * @Description: 随机生成材料
   */
  ranMaterial() {
    return this.materialIndex[Math.floor(Math.random() * this.materialIndex.length)];
  }

  /**
   * @author CHZH
   * @date 2018/5/5 0005
   * @Description: 随机生成价格
   */
  ranPrice() {
    return (Math.floor(Math.random() * 50) + 0.99).toFixed(2);
  }

  /**
   * @author CHZH
   * @date 2018/5/5 0005
   * @Description: 随机生成地点
   */
  ranAddr() {
    const random = Math.floor(Math.random() * this.address2.length);
    return {
      add1: this.address1[0],
      add2: this.address2[random].name,
      add3: this.address2[random].list[Math.floor(Math.random() * this.address2[random].list.length)]
    }
  }

  /**
   * @author CHZH
   * @date 2018/5/5 0005
   * @Description: 随机生成状态
   */

  ranStatus(f) {
    if(f){
      return this.status[Math.floor(Math.random() * this.status.length)];
    }else{
      return this.status[Math.floor(Math.random() * 4) + this.status.length-4]
    }

  }


  /**
   * @author CHZH
   * @date 2018/5/5 0005
   * @Description: 随机生成电话
   */

  ranTel(){
    while(true) {
      let tel = '18' + (Math.floor(Math.random() * 10)) + (5000 + Math.floor(Math.random() * 5000)) + (1000 + Math.floor(Math.random() * 9000));
      if(!this.telStore.has(tel)){
        this.telStore.add(tel);
        return tel;
      }
    }

  }

  /**
   * @author CHZH
   * @date 2018/5/5 0005
   * @Description: 随机生成日期
   */
  ranDate() {
    let dataA = new Date();
    let dataB = new Date();
    dataB.setTime(dataA.getTime() - Math.floor(Math.random() * 10000000000));
    return dataB;
  }

  /**
   * @author CHZH
   * @date 2018/5/5 0005
   * @Description: 初始化
   */
  init() {
    /**
     * @author CHZH
     * @date 2018/5/16 0016
     * @Description: 重置材料列表
     */
    this.materialIndex=[];
    let tempset=new Set();
    for (const item of this.menu) {
      for (const listElement of item.list) {
        tempset.add(listElement);
      }
    }
    this.materialIndex=[...tempset];
    /**
     * @author CHZH
     * @date 2018/5/5 0005
     * @Description: 随机生成用户','工作人员
     */

    for (let i = 12000; i < 13000; i++) {
      const tadd=this.ranAddr();
      const add4=Math.floor(Math.random()*300+1)+'号'+Math.floor(Math.random()*10+1)+'单元'+Math.floor(Math.random()*30+1)+'0'+Math.floor(Math.random()*5+1);
      const add=tadd.add1+tadd.add2+tadd.add3+add4;
      const ranInfo={
        username: this.ranName(),
        password: '123456',
        telephone:this.ranTel(),
        address:add,
        add1:tadd.add1,
        add2:tadd.add2,
        add3:tadd.add3,
        add4:add4,
        id: ('100' + i.toString())
      };
      this.userMap.set(ranInfo.telephone,this.userList.length);
      this.userList.push(ranInfo);

    }
    {
      const tadd=this.ranAddr();
      const add4=Math.floor(Math.random()*300+1)+'号'+Math.floor(Math.random()*10+1)+'单元'+Math.floor(Math.random()*30+1)+'0'+Math.floor(Math.random()*5+1);
      const add=tadd.add1+tadd.add2+tadd.add3+add4;
      const ranInfo={
        username: '陈宗豪',
        password: '111',
        telephone:'18742020281',
        address:add,
        add1:tadd.add1,
        add2:tadd.add2,
        add3:tadd.add3,
        add4:add4,
        id: ('10013000')
      };
      this.userMap.set(ranInfo.telephone,this.userList.length);
      this.userList.push(ranInfo);
    }
    for (let i = 1000; i < 2000; i++) {
      this.senderList.push({
        username: this.ranName(),
        password: '123456',
        telephone:this.ranTel(),
        id: ('20' + i).substr(-5)
      });
    }
    for (let i = 0; i < 11; i++) {
      const tadd=this.ranAddr();
      const add4=Math.floor(Math.random()*300+1)+'号'+Math.floor(Math.random()*10+1)+'单元'+Math.floor(Math.random()*30+1)+'0'+Math.floor(Math.random()*5+1);
      const add=tadd.add1+tadd.add2+tadd.add3+add4;
      const ranInfo={
        username: this.ranName(),
        password: '123456',
        telephone:this.ranTel(),
        address:add,
        add1:tadd.add1,
        add2:tadd.add2,
        add3:tadd.add3,
        add4:add4,
        id: ('000' + i).substr(-4)
      };
      this.managerMap.set(ranInfo.telephone,this.managerList.length);
      this.managerList.push(ranInfo);
    }

    /**
     * @author CHZH
     * @date 2018/5/5 0005
     * @Description: 随机生成分店
     */
    for (let i = 0; i < 10; i++) {
      let map = new Map();
      for (let j = 0; j < this.materialIndex.length; j++) {
        map.set(this.materialIndex[Math.floor(Math.random() * this.materialIndex.length)], Math.floor(Math.random() * 500));
      }
      let k=1;
      this.branchStore[i]=[];
      for (const [key,value] of map.entries()) {
        this.branchStore[i].push({
          id:k++,
          name:key,
          last:value,
        })
      }

      this.branchList.push({
        id: i,
        address: this.ranAddr(),
        add4:Math.floor(Math.random()*300+1)+'号',
        manager: this.managerList[i],
        store: map
      })
    }
    /**
     * @author CHZH
     * @date 2018/5/6 0006
     * @Description: 生成库存信息
     */

    for (let i in this.branchList) {
      const enty=this.branchList[i].store;
      for (const [key,value] of enty.entries()) {
        if(this.totalListMap.has(key)){
          this.totalListMap.set(key,this.totalListMap.get(key)+value);
        }else{
          this.totalListMap.set(key,value);
        }
      }
    }
    let i=1;
    for (const[key,value] of this.totalListMap.entries()) {
      this.totalList.push({
        id:i++,
        name:key,
        last:value
      })
    }
    /**
     * @author CHZH
     * @date 2018/5/5 0005
     * @Description: 随机生成订单
     */

    for (let i = 0; i < this.ordernum; i++) {
      const branchnum=Math.floor(Math.random() * 10);
      const Ndate=new Date();
      const Tdate=this.ranDate();
      let Tstatus;
      if((Ndate.getTime()-Tdate.getTime())>1000*60*60*5){
        Tstatus=this.ranStatus(false);
      }else{
        Tstatus=this.ranStatus(true);
      }
      const ranMenu=this.menu[Math.floor(Math.random()*this.menu.length)];
      const ranUser=this.userList[Math.floor(Math.random() * this.userList.length)];
      const temporder={
        id:i,
        status: Tstatus,
        branch: branchnum,
        sender: this.senderList[Math.floor(Math.random() * this.senderList.length)].username,
        time: Tdate.toLocaleString(),
        date: Tdate.getTime(),
        menu:ranMenu,
        price: '￥'+ranMenu.price,
        user: ranUser.username,
        tUser:ranUser,
        material: ranMenu.list[0],
        burdening: ranMenu.list[1]
      };
      this.orderList.push(temporder);
      if(!ranUser.order) ranUser.order=[];
      ranUser.order.push(temporder);
    }
    this.orderList.sort((a,b)=>b.date-a.date);
    for (let i = 0; i < this.ordernum; i++) {
      if(!this.branchOrder[this.orderList[i].branch]) this.branchOrder[this.orderList[i].branch]=[];
      this.branchOrder[this.orderList[i].branch].push(i);
    }
  }
}


